package com.example.opengl.render.video

import android.opengl.GLES20
import android.opengl.GLSurfaceView
import com.example.opengl.render.base.IDrawer
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class VideoRender(drawer: IDrawer) :GLSurfaceView.Renderer {
    val iDrawer: IDrawer = drawer
    override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) {
        GLES20.glClearColor(0f, 0f, 0f, 0f)
        val texture = IntArray(1)
        GLES20.glGenTextures(1, texture, 0) //生成纹理
        iDrawer.setTextureID(texture[0])
    }

    override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
        GLES20.glViewport(0, 0, width, height)
        iDrawer.setWorldSize(width, height)
    }

    override fun onDrawFrame(gl: GL10?) {
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT or GLES20.GL_DEPTH_BUFFER_BIT)
        iDrawer.draw()
    }



}